package com.fpd.tools;

import org.springframework.beans.factory.annotation.Value;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static cn.afterturn.easypoi.excel.entity.enmus.CellValueType.Date;

/**
 * @desc 根据出生日期计算年龄(精确到天)
 * @author wujiangbo
 * @date 2019年12月30日 下午4:52:15
 */
public class TxtUtil {

	public static void main(String[] args) {
//		List<String> stringList = new ArrayList<>();
//		        stringList.add("1哈哈 黑");
//		        stringList.add("2嘿嘿 黑111");
//		        String name = writeDataHubData(stringList, "111");
//		System.out.println(name);
//		        try {
//					Runtime.getRuntime().exec("cmd /c \\temp\\txt\\"+name);
//				}catch (Exception e){}
		String eL ="(\\d{4})/(\\d{2})/(\\d{2})";
		Pattern p = Pattern.compile(eL);
		Matcher m = p.matcher("2005/32/06 ");
		boolean b = m.matches();
		System.out.println(b);
	}

	public static String writeDataHubData(List<String> result, String fileName) {
		     long start = System.currentTimeMillis();// //获得系统的时间
		     String filePath = "/hecheng/temp/";
		     StringBuilder content = new StringBuilder();
		     boolean flag = false;
		     BufferedWriter out = null;
		     try {
		             if (result != null && !result.isEmpty() && StringUtils.isNotNull(fileName)) {
		             	//"_" + System.currentTimeMillis() +
			          fileName += ".doc";
			          File pathFile = new File(filePath);
			          if (!pathFile.exists()) {
			                  pathFile.mkdirs();//就算父类文件夹不纯在他也可以创建子文件夹
			              }
			          String relFilePath = filePath + File.separator + fileName;//ile.separator 的作用相当于 ' \  '
			          File file = new File(relFilePath);
			          if (!file.exists()) {
			                  file.createNewFile();
			          }
			          out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "GBK"));
						 java.util.Date date = new Date();
						 SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			            //标题头
			            out.write(dateFormat.format(date)+" "+fileName);
			            out.newLine();
			          for (String info : result) {

			                  out.write(info);
			                  out.newLine();//换行
			              }
			          flag = true;
			          System.out.println("写入文件耗时：*********************************" + (System.currentTimeMillis() - start) + "毫秒");
			      }
		         } catch (IOException e) {
		             e.printStackTrace();
		         } finally {
		             if (out != null) {
			            try {
			                    out.flush();//刷新
			                    out.close();//关流
			                } catch (IOException e) {
			                    e.printStackTrace();
			                }
			        }
		             return fileName;
		         }
		 }

}
